package com.arvin.service.serviceImpl;

import com.arvin.mapper.LogMapper;
import com.arvin.pojo.Log;
import com.arvin.pojo.PageBean;
import com.arvin.service.LogService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private LogMapper logMapper;

    /**
     * 新增日志
     * @param log
     */
    @Override
    public void insert(Log log) {
        logMapper.insert(log);
    }

    /**
     * 日志分页
     * @param username
     * @param logType
     * @param logBeginTime
     * @param logEndTime
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public PageBean getLogInfo(String username, String logType, LocalDate logBeginTime, LocalDate logEndTime, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        Page<Log> logPage = logMapper.getLogInfo(username,logType,logBeginTime,logEndTime);
        PageBean pageBean = new PageBean(logPage.getTotal(),logPage.getResult());
        return pageBean;
    }

    /**
     * 获取全部日志信息
     * @return
     */
    @Override
    public List<Log> getAllLog() {
        return logMapper.getAllLog();
    }

    /**
     * 根据id删除日志
     * @param logIds
     */
    @Override
    public void deleteLogByIds(List<Integer> logIds) {
        logMapper.deleteLogByIds(logIds);
    }
}
